<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(isset($_SESSION['lang']))
    require_once "./language_files/resubmitPaper_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/resubmitPaper_en.php";

require_once "functions.php";
if(isset($_GET['conference_id']))
{
// Get the ID
    $cID=intval($_GET['conference_id']);
    $conferenceid=mysql_real_escape_string($cID);
}
$confname=get_conference_name($conferenceid);
echo"</br><span class=breadcrumbs><a href='subscriberConferencePage.php?conference_id={$conferenceid}'>" . $confname . "</a>" . " > " . $lang['resubmit'] . "</span> </br></br>";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <?php include 'jquery.php';?>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                check_top();
            });
        </script>
        <script type="text/javascript">
            //<![CDATA[
            function validate(e)
            {
                //get the value of the element paper
                text = document.getElementById("paper").value;
                //get the last index of the "\"
                var indexOfSlash = text.lastIndexOf('\\');
                //get the file name which is the after the last "\" and set it to a variable
                var file = text.substring(indexOfSlash + 1);

                //                alert(text);
                //                return false;
                //                arr=[","," ",";","'",">","<", ":","/","\\","?"];
                //                for(i=0; i<arr.length; i++ )
                //                {
                //                    //                        alert(text.indexOf(arr[i]));
                //                    //                        alert(text.indexOf(arr[i]) != -1);
                //                    if(file.indexOf(arr[i]) != -1)
                //                    {
                //                        alert ("Warning! Illegal filename!");
                //                        return false;
                //                    }
                //                    //                            break;
                //                }
                //                return true;
                //check if there is any illegal character in the file name using regular expressions then print a message for the user
                /*if(file.match(/^[\w\.]+$/) == null) {
                    alert ("Warning! Illegal filename!");
                    return false;
                }*/
                return true;
            }
            //]]>
        </script>
        <title></title>
    </head>
    <body>
        <form action= ""  method="post" enctype="multipart/form-data"  onsubmit="return validate(this)" >
            <input type="file" name="paper" accept="pdfs" id="paper" />  <br/>
            <input type="submit" name="resubmit" value="<?php echo $lang['submit'];?>" />
            <br/>
            <?php
// Check if a file has been resubmitted
            if(isset($_FILES['paper']))
            {
// Make sure the file was sent without errors
                if($_FILES['paper']['error'] == 0)
                {
                    //Open connection with database
                    $conn=@mysql_connect("localhost","root","") or die(mysql_error());
                    mysql_select_db("mydb") or die(mysql_error());
// Make sure an ID was passed
                    if(isset($_GET['paper_id']))
                    {
// Get the ID
                        $pID=intval($_GET['paper_id']);
                        $paperid=mysql_real_escape_string($pID);
                    }
                    //check if the size of the file exceeds 1 MB the maximum size then print a message for the user
                    if($_FILES['paper']['size'] > 1000000)
                    {
                        echo $lang['text_1'];
                    }
                    else
                    {
                        //check if the file type is not pdf so print a message for the user since the allowed type is pdf only
                        if($_FILES['paper']['type'] != 'application/pdf')
                        {
                            echo $lang['text_2'];
                        }
                        //if its type is pdf so continue submitting
                        else
                        {
                            //if the user click the submit button
                            if(isset($_POST['resubmit']))
                            {

                                //select the version of the paper selected to resubmit it and fetch it.
                                $getVersionID="SELECT `version_id` FROM `Version` WHERE `paper_id`= $paperid  ORDER BY version_id DESC";
                                $getversionid=mysql_query($getVersionID) or die(mysql_error());
                                $versionID=mysql_fetch_assoc($getversionid);
                                //get the new path of the paper
                                $target_path="./paper/" . $_FILES['paper']['name'] . "_" . $versionID["version_id"];
                                move_uploaded_file($_FILES['paper']['tmp_name'],$target_path);

                                // add the new version of the paper with its path
                                $AddNewVersion="INSERT INTO `Version` (`paper_id`,`path`)
                     VALUES ($paperid,'{$target_path}')";
                                //take the autoincremented version id
                                include ("statics.php");
                                // Execute the query
                                mysql_query($AddNewVersion) or die(mysql_error());
                                $last_autoincrement_versionid=mysql_insert_id();
                                exec("pdftohtml -c -noframes " . escapeshellcmd($target_path));
                                iReformat($last_autoincrement_versionid);
                                // Check if it was successfull
                                if($AddNewVersion)
                                { // if the query run successfully
                                    echo $lang['text_3'];
                                }
                                else
                                {
                                    echo $lang['text_4'];
                                }
// Close the mysql connection
                            }
                        }
                    }
                }
                else
                {
                    echo $lang['text_5'];
                }
            }
            ?>
        </form>
    </body>
</html>





